﻿using GalaSoft.MvvmLight.Command;
using Glorysoft.Auto.Xfw;
using Glorysoft.EAP.EAPClient.Model;
using Serilog.Core;
using System;
using System.Collections.ObjectModel;

namespace Glorysoft.EAP.EAPClient.ViewModel
{
    public class LogWindowViewModel : PopupWindowVM
    {
        private readonly Logger ServiceLogger = XfwContext.EapLogger;
        public delegate void CloseDelegate();
        public event CloseDelegate CloseEvent;
        public LogWindowViewModel()
        {
            EqpName = GlobalData.Current.EqpName;
            MSG = GlobalData.Current.MSG;
        }
        private string _EqpName;
        public string EqpName
        {
            get { return _EqpName; }
            set
            {
                _EqpName = value;
                RaisePropertyChanged("EqpName");
            }
        }
        /// <summary>
        /// 实时消息提示
        /// </summary>
        private ObservableCollection<InstantMsg> msg = new ObservableCollection<InstantMsg>();
        public ObservableCollection<InstantMsg> MSG
        {
            get { return msg; }
            set
            {
                msg = value;
                RaisePropertyChanged("MSG");
            }
        }
        /// <summary>
        /// 扫描历史选中位置
        /// </summary>
        private InstantMsg _ItemSelected;
        public InstantMsg ItemSelected
        {
            get { return _ItemSelected; }
            set
            {
                _ItemSelected = value;
                RaisePropertyChanged("ItemSelected");
            }
        }
        private RelayCommand cancelCmd;
        public RelayCommand CancelCmd
        {
            get { return cancelCmd ?? (cancelCmd = new RelayCommand(Cancel)); }
        }
        public void Cancel()
        {
            try
            {
                if (CloseEvent != null)
                    CloseEvent();
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
            this.Close();
        }
    }
}
